{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "%matplotlib inline\n",
    "import json\n",
    "from iclientpy.rest.apifactory  import APIFactory\n",
    "from iclientpy.data.featuresconverter import to_geodataframe_features,from_geodataframe_features\n",
    "from iclientpy.jupyter.widgets.mapview import MapView\n",
    "from ipyleaflet import GeoJSON\n",
    "from iclientpy.dtojson import to_json_str"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "api = APIFactory('http://192.168.20.182:8090/iserver','admin','SuperMap123')\n",
    "ds=api.data_service('data-World/rest')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "frs=ds.get_featureResults()\n",
    "fr=ds.get_featureResult(frs[0].name)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'{\"newResourceID\": \"8b9abf652a7442dab6e4b4877a09a906_c312851f180b4f1dbb3229e213a42eeb\", \"newResourceLocation\": \"http://192.168.20.182:8090/iserver/services/data-World/rest/data/featureResults/8b9abf652a7442dab6e4b4877a09a906_c312851f180b4f1dbb3229e213a42eeb.json\", \"postResultType\": \"CreateChild\", \"succeed\": true}'"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "features=(ds.get_feature_by_url(url) for url in fr.featureUriList)\n",
    "gdf=to_geodataframe_features(features)\n",
    "features=list(feature for feature in from_geodataframe_features(gdf))\n",
    "result=ds.post_features('World','Capitals',features)\n",
    "to_json_str(result)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "features=(ds.get_feature_by_url(url) for url in fr.featureUriList)\n",
    "gdf1=to_geodataframe_features(features)\n",
    "buffer=gdf1.buffer(1)\n",
    "gdf1['geometry']=gdf1.buffer(1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "ff2ab46b693e4933bd28adc0c68b844e",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "MapView(basemap={'url': 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', 'max_zoom': 19, 'attribution': '…"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "layer=GeoJSON(data=json.loads(gdf1.to_json()))\n",
    "map=MapView()\n",
    "map.zoom=1\n",
    "map.add_layer(layer)\n",
    "map"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
